package com.getpebble.android.jskit.bridge;

import java.lang.ref.WeakReference;

public class JsDeveloperConnectionBridge {
    private static JsDeveloperConnectionBridge sInstance;
    private WeakReference<IJsLogSender> mLogSenderWeakReference;

    public static JsDeveloperConnectionBridge getInstance() {
        if (sInstance == null) {
            sInstance = new JsDeveloperConnectionBridge();
        }
        return sInstance;
    }

    public void setLogSender(IJsLogSender sender) {
        this.mLogSenderWeakReference = new WeakReference(sender);
    }

    public void logMessage(String text) {
        if (this.mLogSenderWeakReference != null) {
            IJsLogSender sender = (IJsLogSender) this.mLogSenderWeakReference.get();
            if (sender == null) {
                this.mLogSenderWeakReference = null;
            } else {
                sender.sendJsAppLogLine(text);
            }
        }
    }
}
